<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:set name="date_type" value="%{@com.japp.tools.common.SelectVal@getDataToDateType(rd.date_type)}"></s:set>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户更新</title>
<s:include value="/app_common/common.jsp"></s:include>
<s:include value="/app_common/uploadifyExcel.jsp"></s:include>
<!-- 表单验证start -->
<script src="<s:property value='webctx'/>/libs/js/form/validationRule.js" type="text/javascript"></script>
<script src="<s:property value='webctx'/>/libs/js/form/validation.js" type="text/javascript"></script>
<!-- 表单验证end -->
<style type="text/css">
	input[readonly="readonly"]{
		color: red;
		font-weight:bold;
		cursor: pointer;
	}
	.checkJ td{
		text-align: center;
	}
	.checkJ{
		font-size:12px;
		width:100%;
		border-top-color:#cccccc;
		border-right-color:#cccccc;
		border-bottom-color:#cccccc;
		border-left-color:#cccccc;
		border-top-width:1px;
		border-right-width:1px;
		border-bottom-width:1px;
		border-left-width:1px;
		border-top-style:solid;
		border-right-style: solid;
		border-bottom-style: solid;
		border-left-style: solid;
		border-collapse: collapse;
		background-color:white;
	}
</style>
</head>
<body>
	<div style="text-align: center;font-weight: bold;">风控交易导入<s:property value="rd.id==0?'新增':'修改'"/>(<s:property value="date_type"/>)</div>
		<form name="form2" id="form2" method="post" target="frmright">
		<s:hidden name="rd.date_type"></s:hidden>
			<s:if test="rd.id!=0">
				<%--所属人编码 --%>
				<s:hidden name="rd.submit_ucode" id="rd_submit_ucode"></s:hidden>
				<%--所属人名称 --%>
				<s:hidden name="rd.submit_uname" id="rd_submit_uname"></s:hidden>
				<%--所属分部--%>
				<s:hidden name="rd.submit_dpid" id="rd_submit_dpid"></s:hidden>
				<%--所属分部名称--%>
				<s:hidden name="rd.submit_dpname" id="rd_submit_dpname"></s:hidden>
			</s:if>
			<s:else>
				<%--所属人编码 --%>
				<s:hidden name="rd.submit_ucode" id="rd_submit_ucode" value="%{#session.u_code}"></s:hidden>
				<%--所属人名称 --%>
				<s:hidden name="rd.submit_uname" id="rd_submit_uname" value="%{#session.u_name}"></s:hidden>
			<%--所属分部ID--%>
				<s:hidden name="rd.submit_dpid" id="rd_submit_dpid" value="%{#session.userltd}"></s:hidden>
				<%--所属分部名称--%>
				<s:hidden name="rd.submit_dpname" id="rd_submit_dpname" value="%{#session.userltdname}"></s:hidden>
			</s:else>
			<s:hidden name="rd.id" id="rd_id"></s:hidden>
			<table class="checkJ" style="line-height: 30px">
				<tr>
					<td align="center">选择数据:</td>
					<td align="left" style="padding: 2px 6px;text-align: left;">
						<div style="color: red;">小提示：附件上传EXCEL解析文件数为1个</div>
						<div id="full"></div>
						<div id="allShow"></div>
						<div id="show"></div>
						<input type="file" keepDefaultStyle="true" name="uploadify" id="strutsUploadFile" />
						<br />
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center">
					<input type="button" id="btn0" onclick="back()" value="返回" />&nbsp;&nbsp; 
					<input type="button" id="btn1" onclick="checkSubmit(false)" value="预览" />
					</td>
				</tr>
				<tr id="open" keepDefaultStyle="true" style="display: none;">
					<td colspan="2">
						<table id="go" class="checkJ" width="100%">
							<tr  id="ab">
								<th>序号</th>
								<th>经纪编码</th>
								<th>经纪人</th>
								<th>日期</th>
								<th>手续费</th>
								<th>上交手续费</th>
								<th>手续费收入</th>
								<th>交易额</th>
								<th>客户权益</th>
								<th>可用资金</th>
								<th>总盈亏</th>
								<th>操作</th>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</form>
</body>
<script type="text/javascript">
	var status = "<s:property value='rd.id' />";
	function checkSubmit(obj) {
		$('#strutsUploadFile').uploadifySettings('script',webctx+'/reality/rd_uploadExcel.action');
		$('#strutsUploadFile').uploadifyUpload();
		if($('#btn1').val()=="预览"||obj){
			return false;
		}
		if($('tr[id^="tr_"]').length==0){
			top.Dialog.alert("请选择附件上传，来预览您的Execl内容!");
			return false;
		}
		if(!bool){
			top.Dialog.confirm("显示为红色的数据不正确,确认提交数据(不包括错误的)？",function(){
				checkSubmitChil();
			});
			return false;
		}
		checkSubmitChil();
	}
	
	function checkSubmitChil(){
		var actionUrl;
		if (status == "0") {
			actionUrl = webctx + "/reality/rd_insertRiskDealById.action";
		} else {
			actionUrl = webctx + "/reality/rd_updateRiskDealById.action";
		}
		var actionData = $("#form2").serialize();
		showProgressBar();
		$.ajax({
			url : actionUrl,
			data : actionData,
			type : "post",
			cache : false,
			dataType : 'text',
			success : function(data) {
				if (data != 0) {
					alert('成功导入'+data+'记录!');
					if (status == 0) {
						window.location = webctx + "/reality/rd_queryRiskDeal.action?rd.date_type=<s:property value='rd.date_type'/>";
					}
				} else {
					alert('操作失败!');
				}
				closeProgress();
			}
		});
	}
	
	
	function back() {
		top.Dialog.confirm("确认返回？", function() {
			showProgressBar();
			window.location = webctx + "/reality/rd_queryRiskDeal.action?rd.date_type=<s:property value='rd.date_type'/>";
		});

	}
	function strDateTime(str){
		var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
		if(r==null)return false; 
		var d= new Date(r[1], r[3]-1, r[4]); 
		return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
	}
	var bool = true;
	function Json_val(obj){
		var json_val = obj;
		if(json_val=="ERROR"){
			top.Dialog.alert("请检查文件类型或文件标签时间是否正确!");
			return false;
		}
		json_val = json_val.toJSON();
		var json = json_val[0]['rdList'];
		var checkcode = json_val[0]['rdMap'];
		var array = null;
		var str = "";
		if(json!=null&&json.length>0){
			$('tr[id^="tr_"]').remove();
			for(var i=0;i<json.length;i++){
				bool = true;
				obj = json[i];
				if(obj!=null){
					//r = strDateTime(obj.submit_date);
					//if(!r){
					//	bool = false;
					//}
					if(checkcode[obj.submit_ucode]==null){
						bool = false;
					}
					if(obj.bool){
						array = checkcode['njkh004'].split('!');
						str +="<tr "+(!bool?"style='color:red' title='没有检索到该业务人员!'":'')+
						" id=\"tr_"+i+"\">"+
						"<td>"+(i+1)+
						getInput('submit_dpid',array[0],i,bool)+
						getInput('submit_dpname',array[1],i,bool)+
						getInput('date_type','0',i,bool)
						+"</td>"+
						"<td>"+obj.submit_ucode+getInput('submit_ucode',obj.submit_ucode,i,bool)+"</td>"+
						"<td>"+obj.submit_uname+getInput('submit_uname',obj.submit_uname,i,bool)+"</td>"+
						"<td>"+obj.submit_date+getInput('submit_date',obj.submit_date,i,bool)+"</td>"+
						"<td>"+obj.sxf+getInput('sxf',obj.sxf,i,bool)+"</td>"+
						"<td>"+obj.sjsxf+getInput('sjsxf',obj.sjsxf,i,bool)+"</td>"+
						"<td>"+obj.sxfsr+getInput('sxfsr',obj.sxfsr,i,bool)+"</td>"+
						"<td>"+obj.jre+getInput('jre',obj.jre,i,bool)+"</td>"+
						"<td>"+obj.khqy+getInput('khqy',obj.khqy,i,bool)+"</td>"+
						"<td>"+obj.kyzj+getInput('kyzj',obj.kyzj,i,bool)+"</td>"+
						"<td>"+obj.zky+getInput('zky',obj.zky,i,bool)+"</td>"+
						"<td><span class=\"img_delete hand\" title=\"删除\" onclick=\"del_tr('#tr_"+i+"')\"></span></td>";/* 
						str+='<input type="hidden" name="list['+i+'].submit_ucode" value="<s:property value="#session.u_code"/>"/>'+
						'<input type="hidden" name="list['+i+'].submit_uname" value="<s:property value="#session.u_name"/>"/>'+
						'<input type="hidden" name="list['+i+'].submit_dpid" value="<s:property value="#session.userltd"/>"/>'+
						'<input type="hidden" name="list['+i+'].submit_dpname" value="<s:property value="#session.userltdname"/>"/>'; */
						str += "</tr>";
					}else{
						str +="<tr style='color:red' title='数据格式错误!' id=\"tr_"+i+"\">";
						str += "<td colspan='8'>"+obj.error+"</td>"+
						"<td><span class=\"img_delete hand\" title=\"删除\" onclick=\"del_tr('#tr_"+i+"')\"></span></td>";
						str += "</tr>";
					}
				}
			}
			$('#go').append(str);
			$('#open').show();
			$('#btn1').val('确认提交');
			$('#btn3').remove();
			$('#btn0').after("&nbsp;&nbsp;<input type='button' id='btn3' onclick=\"checkSubmit(true)\" value='重新上传预览'>");
			$('#btn3').buttonInputRender();
			}
	}
	function getInput(obj,obj1,obj3,obj4){
		if(!obj4)return '';
		return '<input type="hidden" name="list['+obj3+'].'+obj+'" value="'+obj1+'"/>';
	}
	function del_tr(obj){
		top.Dialog.confirm("确定要删除该记录吗？",function(){
			$(obj).remove();
			if($('tr[id^="tr_"]').length==0){
				$('#open').hide();
			}
		});
		
	}
</script>
</html>